package gdut.imis.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.Certificates;
import gdut.imis.enums.Status;
import gdut.imis.mapper.CertificatesMapper;
import gdut.imis.service.CertificatesService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description 证书档案serviceimpl
 * @Author JiaFu
 * @Date 2023/4/7 13:01
 */
@Service
@RequiredArgsConstructor
public class CertificatesServiceImpl extends ServiceImpl<CertificatesMapper, Certificates> implements CertificatesService {

    private final CertificatesMapper certificatesMapper;

    /***
     * 新增证书档案
     * @param: certificates
     * @return Result
     */
    @Override
    public Result addCertificates(Certificates certificates) {
        if (Objects.isNull(certificates)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "certificates");
        }
        boolean flag = this.save(certificates);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增证书档案失败");
    }

    /***
     * 根据学生id查询学生第一次考取证书的证书档案回忆录
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getCertificateMemoryByStuId(Long studentId) {
        Certificates certificates = certificatesMapper.getCertificateMemoryByStuId(studentId);
        if (Objects.isNull(certificates)) {
            return Result.errorWithArgs(Status.FAILED,"没有查询到该学生的证书档案回忆");
        }
        return Result.success(certificates);
    }
}
